home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr53 / 122_01.zip / PIST2E.C < prev    next >
Text File  |  1993-06-02  |  7KB  |  260 lines

  1. /*********************************************************/
  2. /*                             */
  3. /* PISTOL-Portably Implemented Stack Oriented Language     */
  4. /*            Version 2.0             */
  5. /* (C) 1983 by    Ernest E. Bergmann             */
  6. /*        Physics, Building #16             */
  7. /*        Lehigh Univerisity             */
  8. /*        Bethlehem, Pa. 18015             */
  9. /*                             */
  10. /* Permission is hereby granted for all reproduction and */
  11. /* distribution of this material provided this notice is */
  12. /* included.                         */
  13. /*                             */
  14. /*********************************************************/
  15. /* sixth code module for PISTOL v2.0 in BDS 'C' v1.45a */
  16. /* March 10, 1983 */
  17.  
  18. #include "bdscio.h"
  19. #include "pistol.h"
  20.  
  21. init()
  22. {int psemcol(),wstore(),times(),plus(),subtract(),
  23.     divmod(),pif(),wat(),abort(),sp(),
  24.     load(),pelse(),wrd(),rp(),pop(),
  25.     puser(),exec(),exitop(),lit(),rpop(),
  26.     swap(),ttyi(),tyo(),rpsh(),semicf(),
  27.     rat(),compme(),comphere(),dollarc(),colon(),
  28.     semcol(),ifop(),elseop(),thenop(),doop(),
  29.     loopop(),beginop(),endop(),repet(),geoln(),pdollar(),
  30.     pcolon(),casat(),pdo(),pploop(),plloop(),
  31.     cat(),cstore(),ploop(),dotdot(),semidol(),
  32.     primq(),cordmp(),restor(),sat(),find(),
  33.     listfil(),vfind(),lat(),ofcas(),ccolon(),
  34.     semicc(),ndcas(),pofcas(),pccol(),psemicc(),
  35.     getline(),intoken(),openr(),openw(),
  36.     readl(),writl();
  37.  
  38.     keylen=0;/*March 10, 1983*/
  39.     for (temp=0; temp<RAMSIZE; temp++)
  40.         {ram[temp].in=10000;};
  41.     stkptr=0;
  42.     ram[-21].in=MININT;
  43.     ram[-20].in=MAXLINNO;
  44.     ram[-19].in=CHKLMT;
  45.     ram[-18].pw=nram;
  46.     ram[-17].pc=strings;
  47.     ram[34].in=ram[33].in=ram[32].in=ram[30].in=
  48.         ram[29].in=FALS;
  49.     ram[-16].pc=strings+STRINGSSIZE;
  50.     ram[-15].pw=&ram[VBASE];
  51.     ram[-14].in=VSIZE;
  52.     ram[-13].in=CSIZE;
  53.     ram[-12].in=LSIZE;
  54.     ram[-11].in=RSIZE;
  55.     ram[-10].in=SSIZE;
  56.     ram[-9].pc=&strings[LINEBUF];
  57.     ram[-8].pw=&ram[COMPBUF];
  58.     ram[-7].pw=&ram[RAMSIZE];
  59.     ram[-6].in=MAXORD;
  60.     ram[-5].in=MAXINT;
  61.     ram[-4].in=VERSION;
  62.     ram[-3].in=NEWLINE;
  63.     ram[-2].in=RPROTECT;
  64.     ram[-1].in=WPROTECT;
  65.     ram[27].in=1;
  66.     ram[26].in=ram[25].in=-1;
  67.     ram[23].in=8;    /* init tabsize */
  68.     ram[21].in=ABRT;    /* init endcase to abort */
  69.     ram[19].in=TERMWIDTH;
  70.     ram[17].in=TERMLENGTH;
  71.     ram[16].in=ram[15].in=ram[9].in=ram[8].in=FALS;
  72.     ram[13].in=TRU;
  73.     ram[5].pw=&ram[29];
  74.     ram[2].pw=&ram[45+VSIZE+RSIZE];
  75.     ram[3].pc=ram[4].pc=&strings[CHKLMT+2];
  76.     ram[0].in=10;    /* decimal mode */
  77.     strings[0]='X';
  78.     imagename[0]=namein[0]=namout[0]=listname[0]=
  79.     infil[0]=strings[1]=0;
  80.     readv=addstring(18,"**READ VIOLATION**");
  81.     writv=addstring(19,"**WRITE VIOLATION**");
  82.     divby0=addstring(16,"DIVISION BY ZERO");
  83.     nopen=addstring(20,"*** FILE NOT OPENED*");
  84.     feof=addstring(20,"*** EOF ENCOUNTERED*");
  85.     id=addstring(18,"*** PISTOL 2.0 ***");
  86.     synt=addstring(20,"*** SYNTAX ERROR ***");
  87.     ovflo=addstring(19,"** STACK OVERFLOW *");
  88.     undflo=addstring(19,"* STACK UNDERFLOW *");
  89.     redef=addstring(16,"---REDEFINING---");
  90.  
  91.     farray[PSEMICOL]=psemcol;
  92.     farray[WSTORE]=wstore;
  93.     farray[TIMES]=times;
  94.     farray[PLUS]=plus;
  95.     farray[SUBTRACT]=subtract;
  96.     farray[DIVMOD]=divmod;
  97.     farray[PIF]=pif;
  98.     farray[WAT]=wat;
  99.     farray[ABRT]=abort;
  100.     farray[SP]=sp;
  101.     farray[LOAD]=load;
  102.     farray[PELSE]=pelse;
  103.     farray[WRD]=wrd;
  104.     farray[RP]=rp;
  105.     farray[DROPOP]=pop;
  106.     farray[PUSER]=puser;
  107.     farray[EXEC]=exec;
  108.     farray[EXITOP]=exitop;
  109.     farray[STRLIT]=farray[LIT]=lit;
  110.     farray[RPOP]=rpop;
  111.     farray[SWP]=swap;
  112.     farray[TYI]=ttyi;
  113.     farray[TYO]=tyo;
  114.     farray[RPSH]=rpsh;
  115.     farray[SEMICF]=semicf;
  116.     farray[RAT]=rat;
  117.     farray[COMPME]=compme;
  118.     farray[COMPHERE]=comphere;
  119.     farray[DOLLARC]=dollarc;
  120.     farray[COLON]=colon;
  121.     farray[SEMICOLON]=semcol;
  122.     farray[IFOP]=ifop;
  123.     farray[ELSEOP]=elseop;
  124.     farray[THENOP]=thenop;
  125.     farray[DOOP]=doop;
  126.     farray[LOOPOP]=loopop;
  127.     farray[BEGINOP]=beginop;
  128.     farray[ENDOP]=endop;
  129.     farray[REPET]=repet;
  130.     farray[PERCENT]=geoln;
  131.     farray[PDOLLAR]=pdollar;
  132.     farray[PCOLON]=pcolon;
  133.     farray[CASAT]=casat;
  134.     farray[PDOOP]=pdo;
  135.     farray[PPLOOP]=pploop;
  136.     farray[PLLOOP]=plloop;
  137.     farray[CAT]=cat;
  138.     farray[CSTORE]=cstore;
  139.     farray[PLOOP]=ploop;
  140.     farray[DOTDOT]=dotdot;
  141.     farray[SEMIDOL]=semidol;
  142.     farray[PRMQ]=primq;
  143.     farray[CORDMP]=cordmp;
  144.     farray[RESTOR]=restor;
  145.     farray[SAT]=sat;
  146.     farray[FINDOP]=find;
  147.     farray[LISTFIL]=listfil;
  148.     farray[VFINDOP]=vfind;
  149.     farray[LAT]=lat;
  150.     farray[OFCAS]=ofcas;
  151.     farray[CCOLON]=ccolon;
  152.     farray[SEMICC]=semicc;
  153.     farray[NDCAS]=ndcas;
  154.     farray[POFCAS]=pofcas;
  155.     farray[PCCOL]=pccol;
  156.     farray[PSEMICC]=psemicc;
  157.     farray[GTLIN]=getline;
  158.     farray[WORD]=intoken();
  159.     farray[OPENR]=openr;
  160.     farray[OPENW]=openw;
  161.     farray[READL]=readl;
  162.     farray[WRITL]=writl;
  163.     penter(2,"W!",WSTORE);
  164.     penter(1,"*",TIMES);
  165.     penter(1,"+",PLUS);
  166.     penter(1,"-",SUBTRACT);
  167.     penter(4,"/MOD",DIVMOD);
  168.     penter(2,"W@",WAT);
  169.     penter(5,"ABORT",ABRT);
  170.     penter(2,"SP",SP);
  171.     penter(4,"LOAD",LOAD);
  172.     penter(1,"W",WRD);
  173.     penter(2,"RP",RP);
  174.     penter(4,"DROP",DROPOP);
  175.     penter(4,"USER",PUSER);
  176.     penter(4,"EXEC",EXEC);
  177.     penter(4,"EXIT",EXITOP);
  178.     penter(2,"R>",RPOP);
  179.     penter(4,"SWAP",SWP);
  180.     penter(3,"TYI",TYI);
  181.     penter(3,"TYO",TYO);
  182.     penter(2,"<R",RPSH);
  183.     penter(2,";F",SEMICF);
  184.     penter(2,"R@",RAT);
  185.     penter(2,"$:",-DOLLARC);
  186.     penter(1,":",-COLON);
  187.     penter(1,";",-SEMICOLON);
  188.     penter(2,"IF",-IFOP);
  189.     penter(4,"ELSE",-ELSEOP);
  190.     penter(4,"THEN",-THENOP);
  191.     penter(2,"DO",-DOOP);
  192.     penter(4,"LOOP",-LOOPOP);
  193.     penter(5,"BEGIN",-BEGINOP);
  194.     penter(3,"END",-ENDOP);
  195.     penter(6,"REPEAT",-REPET);
  196.     penter(1,"%",-PERCENT);
  197.     penter(5,"CASE@",CASAT);
  198.     penter(5,"+LOOP",-PLLOOP);
  199.     penter(2,"C@",CAT);
  200.     penter(2,"C!",CSTORE);
  201.     penter(2,"..",DOTDOT);
  202.     penter(2,";$",-SEMIDOL);
  203.     penter(10,"PRIMITIVE?",PRMQ);
  204.     penter(8,"COREDUMP",CORDMP);
  205.     penter(7,"RESTORE",RESTOR);
  206.     penter(2,"S@",SAT);
  207.     penter(4,"FIND",FINDOP);
  208.     penter(8,"LISTFILE",LISTFIL);
  209.     penter(5,"VFIND",VFINDOP);
  210.     penter(2,"L@",LAT);
  211.     penter(6,"OFCASE",-OFCAS);
  212.     penter(2,"C:",-CCOLON);
  213.     penter(2,";C",-SEMICC);
  214.     penter(7,"ENDCASE",-NDCAS);
  215.     penter(4,"(;C)",PSEMICC);
  216.     penter(7,"GETLINE",GTLIN);
  217.     penter(4,"WORD",WORD);
  218.     penter(5,"OPENR",OPENR);
  219.     penter(5,"OPENW",OPENW);
  220.     penter(8,"READLINE",READL);
  221.     penter(9,"WRITELINE",WRITL);
  222. }
  223.  
  224.  
  225. /* addstring - convenience for initialization phase to emplace
  226.     string and update ram[3]
  227. */
  228. char *addstring(length,string)
  229. int length;
  230. char *string;
  231. {
  232. int i;
  233. char *start;
  234.     start=ram[3].pc++;
  235.     movmem(string,ram[3].pc,length);
  236.     ram[3].pc += length;
  237.     permstrings();
  238.     *start=length;
  239.     return(start);
  240. }
  241.  
  242.  
  243. penter(length, name, opcode)
  244. int    length,opcode;
  245. char    *name;
  246. {
  247.     Pc=addstring(length,name);
  248.     append(0);
  249.     append((*ram[5].pw).in);
  250.     append(Pc);
  251.     if(opcode<0)
  252.     {append(-opcode);append(PSEMICOLON);}
  253.     else
  254.     {append(COMPME);append(opcode);}
  255.     (*ram[5].pw).pw = ram[2].pw - 1 ;
  256.     push(ram[2].in);
  257.     fenter();
  258. }
  259. 8,"LISTFILE",LISTFIL);
  260.     penter(5,"VFIND